home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD-Sensation: Golden Games / Amiga CD-Sensation - Ausgabe 2 - Golden Games (1996)(GTI - Schatztruhe)(DE)[!].iso / Archive / Funny Stuff / gsv.lha / main.c < prev    next >
C/C++ Source or Header  |  1995-11-18  |  5KB  |  167 lines

  1.  
  2. #include <intuition/intuition.h>
  3. #include <exec/memory.h>
  4.  
  5. struct IntuitionBase *IntuitionBase;
  6. struct Screen *scr;
  7. struct Window *wind;
  8. struct IntuiMessage *messi;
  9.  
  10. extern UWORD gsvData[13446];
  11. extern struct Image gsv;
  12.  
  13. struct Gadget gad3 =
  14. {
  15.     NULL,
  16.     395, 6,
  17.     19, 19,
  18.     GFLG_GADGHCOMP,
  19.     GACT_RELVERIFY,
  20.     GTYP_BOOLGADGET,
  21.     NULL,
  22.     NULL,
  23.     NULL,
  24.     0,0,3,0
  25. };
  26.  
  27. struct Gadget gad2 =
  28. {
  29.     &gad3,
  30.     344, 117,
  31.     72, 25,
  32.     GFLG_GADGHCOMP,
  33.     GACT_RELVERIFY,
  34.     GTYP_BOOLGADGET,
  35.     NULL,
  36.     NULL,
  37.     NULL,
  38.     0,0,2,0
  39. };
  40. struct Gadget gad1 =
  41. {
  42.     &gad2,
  43.     344, 52,
  44.     72, 25,
  45.     GFLG_GADGHCOMP,
  46.     GACT_RELVERIFY,
  47.     GTYP_BOOLGADGET,
  48.     NULL,
  49.     NULL,
  50.     NULL,
  51.     0,0,1,0
  52. };
  53.  
  54.     int terminate=FALSE;
  55.  
  56. int
  57. main(int argc, char *argv[])
  58. {
  59.     void *mem;
  60.     char pubname[MAXPUBSCREENNAME];
  61.     ULONG oldpalette[8];
  62.     int x, y, rt=0, p=0;
  63.  
  64.     if ((IntuitionBase = (struct IntuitionBase*)OpenLibrary("intuition.library", 36L)) == NULL)
  65.     {
  66.         puts("failed on intuition"); exit(100);
  67.     }
  68.     if ((mem=(void*)AllocVec(sizeof(UWORD)*13446, MEMF_CHIP)) == NULL)
  69.     {
  70.         puts("no chip mem"); CloseLibrary(IntuitionBase); exit(100);
  71.     }
  72.  
  73.     if (argc==2)
  74.         p=atoi(argv[1]);
  75.  
  76.     Delay((ULONG)p);
  77.  
  78.     GetDefaultPubScreen(pubname);
  79.  
  80.     if ((scr = LockPubScreen(pubname)) == NULL)
  81.     { puts("no pubscreen"); FreeVec(mem); CloseLibrary(IntuitionBase); exit(100); }
  82.  
  83.     x=scr->Width; y=scr->Height;
  84.  
  85.     oldpalette[0] = GetRGB4(scr->ViewPort.ColorMap, 0);
  86.     oldpalette[1] = GetRGB4(scr->ViewPort.ColorMap, 1);
  87.     oldpalette[2] = GetRGB4(scr->ViewPort.ColorMap, 2);
  88.     oldpalette[3] = GetRGB4(scr->ViewPort.ColorMap, 3);
  89.     oldpalette[4] = GetRGB4(scr->ViewPort.ColorMap, 4);
  90.     oldpalette[5] = GetRGB4(scr->ViewPort.ColorMap, 5);
  91.     oldpalette[6] = GetRGB4(scr->ViewPort.ColorMap, 6);
  92.     oldpalette[7] = GetRGB4(scr->ViewPort.ColorMap, 7);
  93.  
  94.     SetRGB4(&scr->ViewPort, 0, 0x0, 0x0, 0x0);
  95.     SetRGB4(&scr->ViewPort, 1, 0x8, 0x0, 0x0);
  96.     SetRGB4(&scr->ViewPort, 2, 0x0, 0x8, 0x8);
  97.     SetRGB4(&scr->ViewPort, 3, 0x8, 0x8, 0x8);
  98.     SetRGB4(&scr->ViewPort, 4, 0x0, 0x0, 0x8);
  99.     SetRGB4(&scr->ViewPort, 5, 0xF, 0x0, 0x0);
  100.     SetRGB4(&scr->ViewPort, 6, 0xB, 0xB, 0xB);
  101.     SetRGB4(&scr->ViewPort, 7, 0xF, 0xF, 0xF);
  102.  
  103.     if((wind = (struct Window *) OpenWindowTags(NULL,
  104.         WA_Left, (x-423)/2,
  105.         WA_Top, (y-166)/2,
  106.         WA_Width, 423, WA_Height, 166,
  107.         WA_Borderless, TRUE, WA_Activate, TRUE,
  108.         WA_PubScreenName, pubname,
  109.         WA_IDCMP, IDCMP_GADGETUP|IDCMP_VANILLAKEY,
  110.         WA_Gadgets, &gad1,
  111.         TAG_DONE)) == NULL)
  112.     {
  113.         puts("failed on win"); FreeVec(mem); CloseLibrary(IntuitionBase); exit(100);
  114.     }
  115.  
  116.     UnlockPubScreen(NULL, scr);
  117.  
  118.     CopyMem(gsvData, mem, sizeof(UWORD)*13446);
  119.     gsv.ImageData = mem;
  120.  
  121.     DrawImage(wind->RPort, &gsv, 0, 0);
  122.  
  123.     while (!terminate)
  124.     {
  125.         while ((messi=(struct IntuiMessage *)GetMsg(wind->UserPort)) == NULL)
  126.             WaitPort(wind->UserPort);
  127.  
  128.         if (messi->Class == IDCMP_GADGETUP)
  129.             switch(((struct Gadget *)messi->IAddress)->GadgetID)
  130.             {
  131.                 case 1:
  132.                     rt=0; terminate=TRUE; break;
  133.                 case 2:
  134.                     rt=1; terminate=TRUE; break;
  135.                 case 3:
  136.                     rt=5; terminate=TRUE; break;
  137.             }
  138.         if (messi->Class == IDCMP_VANILLAKEY)
  139.             switch(messi->Code)
  140.             {
  141.                 case 'c':
  142.                 case 'C':
  143.                 case 13:
  144.                     rt=0; terminate=TRUE; break;
  145.                 case 'd':
  146.                 case 'D':
  147.                 case 27:
  148.                     rt=1; terminate=TRUE; break;
  149.             }
  150.         ReplyMsg(messi);
  151.     }
  152.  
  153.     SetRGB4(&scr->ViewPort, 0, (oldpalette[0]& 0xF00)>>8, (oldpalette[0]& 0xF0)>>4, oldpalette[0] & 0xF);
  154.     SetRGB4(&scr->ViewPort, 1, (oldpalette[1]& 0xF00)>>8, (oldpalette[1]& 0xF0)>>4, oldpalette[1] & 0xF);
  155.     SetRGB4(&scr->ViewPort, 2, (oldpalette[2]& 0xF00)>>8, (oldpalette[2]& 0xF0)>>4, oldpalette[2] & 0xF);
  156.     SetRGB4(&scr->ViewPort, 3, (oldpalette[3]& 0xF00)>>8, (oldpalette[3]& 0xF0)>>4, oldpalette[3] & 0xF);
  157.     SetRGB4(&scr->ViewPort, 4, (oldpalette[4]& 0xF00)>>8, (oldpalette[4]& 0xF0)>>4, oldpalette[4] & 0xF);
  158.     SetRGB4(&scr->ViewPort, 5, (oldpalette[5]& 0xF00)>>8, (oldpalette[5]& 0xF0)>>4, oldpalette[5] & 0xF);
  159.     SetRGB4(&scr->ViewPort, 6, (oldpalette[6]& 0xF00)>>8, (oldpalette[6]& 0xF0)>>4, oldpalette[6] & 0xF);
  160.     SetRGB4(&scr->ViewPort, 7, (oldpalette[7]& 0xF00)>>8, (oldpalette[7]& 0xF0)>>4, oldpalette[7] & 0xF);
  161.  
  162.     CloseWindow(wind);
  163.     FreeVec(mem);
  164.     CloseLibrary(IntuitionBase);
  165. }
  166.  
  167.